package search;

/**
 * User: 86156
 * Date: 2023-04-16
 * Time: 10:31
 */
public class Selection {
    public static void main(String[] args) {
        int [] arr = {2,4,5,3,1};

        extracted(arr);

        extracted1(arr);

    }

    private static void extracted1(int[] arr) {
        // 选择排序
        for (int i = 0; i < arr.length-1; i++) {
            for (int j = i+1; j < arr.length; j++) {
                if(arr[i]> arr[j]){
                    int temp = arr[i];
                    arr[i] = arr[j];
                    arr[j] = temp;
                }
            }
        }

        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i]+" ");
        }
    }

    private static void extracted(int[] arr) {
        // 冒泡
        // 外循环  执行的次数
        for (int i = 0; i < arr.length-1; i++) {
            for (int j = 0; j < arr.length-1-i; j++) {
                if(arr[j] > arr[j+1]){
                    int temp = arr[j];
                    arr[j] = arr[j+1];
                    arr[j+1] = temp;
                }
            }
        }

        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i]+" ");
        }
        System.out.println();
    }
}
